package com.uniflow.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDateTime;

/**
 * 审计日志实体类
 * 
 * @author uniflow
 * @since 1.0.0
 */
@ApiModel(description = "审计日志")
public class AuditLogs {

    @ApiModelProperty("日志ID")
    private String id;
    
    @ApiModelProperty("操作用户ID")
    private String userId;
    
    @ApiModelProperty("用户名")
    private String username;
    
    @ApiModelProperty("操作类型")
    private String operationType;
    
    @ApiModelProperty("资源类型")
    private String resourceType;
    
    @ApiModelProperty("资源ID")
    private String resourceId;
    
    @ApiModelProperty("资源名称")
    private String resourceName;
    
    @ApiModelProperty("操作描述")
    private String operationDesc;
    
    @ApiModelProperty("请求IP")
    private String requestIp;
    
    @ApiModelProperty("用户代理")
    private String userAgent;
    
    @ApiModelProperty("请求URL")
    private String requestUrl;
    
    @ApiModelProperty("请求方法")
    private String requestMethod;
    
    @ApiModelProperty("请求参数JSON")
    private String requestParams;
    
    @ApiModelProperty("变更前数据JSON")
    private String oldData;
    
    @ApiModelProperty("变更后数据JSON")
    private String newData;
    
    @ApiModelProperty("操作结果：success/failure")
    private String operationResult;
    
    @ApiModelProperty("错误信息")
    private String errorMessage;
    
    @ApiModelProperty("操作时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime operationTime;
    
    // 关联查询字段
    @ApiModelProperty("操作用户信息")
    private User user;
    
    // 构造函数
    public AuditLogs() {}
    
    public AuditLogs(String userId, String operationType, String resourceType, String resourceId) {
        this.userId = userId;
        this.operationType = operationType;
        this.resourceType = resourceType;
        this.resourceId = resourceId;
        this.operationTime = LocalDateTime.now();
    }
    
    // Getter和Setter方法
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getOperationType() {
        return operationType;
    }
    
    public void setOperationType(String operationType) {
        this.operationType = operationType;
    }
    
    public String getResourceType() {
        return resourceType;
    }
    
    public void setResourceType(String resourceType) {
        this.resourceType = resourceType;
    }
    
    public String getResourceId() {
        return resourceId;
    }
    
    public void setResourceId(String resourceId) {
        this.resourceId = resourceId;
    }
    
    public String getResourceName() {
        return resourceName;
    }
    
    public void setResourceName(String resourceName) {
        this.resourceName = resourceName;
    }
    
    public String getOperationDesc() {
        return operationDesc;
    }
    
    public void setOperationDesc(String operationDesc) {
        this.operationDesc = operationDesc;
    }
    
    public String getRequestIp() {
        return requestIp;
    }
    
    public void setRequestIp(String requestIp) {
        this.requestIp = requestIp;
    }
    
    public String getUserAgent() {
        return userAgent;
    }
    
    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }
    
    public String getRequestUrl() {
        return requestUrl;
    }
    
    public void setRequestUrl(String requestUrl) {
        this.requestUrl = requestUrl;
    }
    
    public String getRequestMethod() {
        return requestMethod;
    }
    
    public void setRequestMethod(String requestMethod) {
        this.requestMethod = requestMethod;
    }
    
    public String getRequestParams() {
        return requestParams;
    }
    
    public void setRequestParams(String requestParams) {
        this.requestParams = requestParams;
    }
    
    public String getOldData() {
        return oldData;
    }
    
    public void setOldData(String oldData) {
        this.oldData = oldData;
    }
    
    public String getNewData() {
        return newData;
    }
    
    public void setNewData(String newData) {
        this.newData = newData;
    }
    
    public String getOperationResult() {
        return operationResult;
    }
    
    public void setOperationResult(String operationResult) {
        this.operationResult = operationResult;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    public LocalDateTime getOperationTime() {
        return operationTime;
    }
    
    public void setOperationTime(LocalDateTime operationTime) {
        this.operationTime = operationTime;
    }
    
    public User getUser() {
        return user;
    }
    
    public void setUser(User user) {
        this.user = user;
    }
    
    /**
     * 操作类型常量
     */
    public static class OperationType {
        public static final String CREATE = "CREATE";
        public static final String UPDATE = "UPDATE";
        public static final String DELETE = "DELETE";
        public static final String LOGIN = "LOGIN";
        public static final String LOGOUT = "LOGOUT";
        public static final String EXPORT = "EXPORT";
        public static final String IMPORT = "IMPORT";
        public static final String APPROVE = "APPROVE";
        public static final String REJECT = "REJECT";
        public static final String DEPLOY = "DEPLOY";
        public static final String START = "START";
        public static final String COMPLETE = "COMPLETE";
        public static final String ASSIGN = "ASSIGN";
        public static final String TRANSFER = "TRANSFER";
    }
    
    /**
     * 资源类型常量
     */
    public static class ResourceType {
        public static final String USER = "USER";
        public static final String ROLE = "ROLE";
        public static final String PERMISSION = "PERMISSION";
        public static final String ORGANIZATION = "ORGANIZATION";
        public static final String PROCESS_DEFINITION = "PROCESS_DEFINITION";
        public static final String PROCESS_INSTANCE = "PROCESS_INSTANCE";
        public static final String TASK = "TASK";
        public static final String FORM = "FORM";
        public static final String FORM_DATA = "FORM_DATA";
        public static final String API_APPLICATION = "API_APPLICATION";
        public static final String API_KEY = "API_KEY";
        public static final String SYSTEM_CONFIG = "SYSTEM_CONFIG";
        public static final String SYNC_SOURCE = "SYNC_SOURCE";
        public static final String SYNC_TASK = "SYNC_TASK";
    }
    
    /**
     * 操作结果常量
     */
    public static class OperationResult {
        public static final String SUCCESS = "success";
        public static final String FAILURE = "failure";
    }
    
    @Override
    public String toString() {
        return "AuditLog{" +
                "id='" + id + '\'' +
                ", userId='" + userId + '\'' +
                ", username='" + username + '\'' +
                ", operationType='" + operationType + '\'' +
                ", resourceType='" + resourceType + '\'' +
                ", resourceId='" + resourceId + '\'' +
                ", operationResult='" + operationResult + '\'' +
                ", operationTime=" + operationTime +
                '}';
    }
}